
/**
 * 调起客户端相机扫码。
 * @description https://uniapp.dcloud.net.cn/api/system/barcode.html
 * @param {Boolean} onlyFromCamera true 是否只允许相机扫码识别
 * @param {Array<string>} scanType ['barCode', 'qrCode', 'datamatrix','datamatrix']
 * @returns Promise 成功返回相关数据结构
 */
function scanCode(
    onlyFromCamera = true,
    scanType = ['barCode', 'qrCode', 'datamatrix', 'datamatrix'],
): Promise<string | UniApp.ScanCodeSuccessRes> {
    // #ifdef H5
    return Promise.reject('不支持H5');
    // #endif
    return new Promise((rs, rj) => {
        uni.scanCode({
            onlyFromCamera: onlyFromCamera,
            scanType: scanType,
            success: res => rs(res),
            fail: error => rj(error),
        });
    });
}

export default scanCode;
